package com.zb.springboot_zb_sql.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    Object exceptionHandler(Exception e, HttpServletRequest httpServletRequest){
        Map<String,Object> map=new HashMap<>();
        map.put("code",500);
        map.put("msg",e.getMessage());
        map.put("data",httpServletRequest.getRequestURI());
        return  map;

    }
    @ExceptionHandler(value = IndexException.class)
    Object IndexHander(IndexException e){
        Map<String,Object> map=new HashMap<>();
        map.put("code",1000);
        map.put("msg",e.getMessage());
        return  map;

    }
}
